<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>父组件和子组件</title>
    <script src="../lib/vue_v2.6.14.js"></script>
  </head>
  <body>
    <div id="app">
      <cpn-par></cpn-par>
    </div>

    <script>
      // 子组件
      const cpnSon = Vue.extend({
        template: `
          <div>
            <h2>{{ title }}</h2>
            <p>我是内容，呵呵呵呵</p>
          </div>
        `,
        data() {
          return {
            title: '我是子组件'
          }
        }
      })

      // 父组件
      const cpnPar = Vue.extend({
        template: `
          <div>
            <h2>{{ title }}</h2>
            <p>我是内容，哈哈哈哈</p>
            <cpn-son></cpn-son>
          </div> 
        `,
        data() {
          return {
            title: '我是父组件'
          }
        },
        components: {
          'cpn-son': cpnSon
        }
      })

      // root组件
      const vm = new Vue({
        el: '#app',
        data: {},
        components: {
          'cpn-par': cpnPar
        }
      })
    </script>
  </body>
</html>
